package com.freak.kotlinfitnessserver.factory

import android.text.TextUtils
import com.freak.kotlinfitnessserver.constant.DeviceConstant
import com.freak.kotlinfitnessserver.factory.response.CrossTrainerResponseFactory
import com.freak.kotlinfitnessserver.factory.response.IndoorBikeResponseFactory
import com.freak.kotlinfitnessserver.factory.response.RowerResponseFactory
import com.freak.kotlinfitnessserver.factory.response.TreadmillResponseFactory
import com.freak.kotlinfitnessserver.util.LogUtil

class ResponseFactory {
    companion object {
        const val TAG: String = "ReadRequestFactory"
    }

    private val readRequestFactory = mutableMapOf<String, IResponseFactory>()

    init {
        readRequestFactory[DeviceConstant.treadmill] = TreadmillResponseFactory()
        readRequestFactory[DeviceConstant.indoorBike] = IndoorBikeResponseFactory()
        readRequestFactory[DeviceConstant.crossTrainer] = CrossTrainerResponseFactory()
        readRequestFactory[DeviceConstant.rower] = RowerResponseFactory()
    }

    fun createFactory(deviceType: String): IResponseFactory? {
        if (TextUtils.isEmpty(deviceType)) {
            LogUtil.e(TAG, "deviceType is error")
            return null
        }
        return readRequestFactory[deviceType]
    }
}